<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/1 0001
 * Time: 上午 9:08
 */

namespace Home\Controller;


class OrderController  extends BaseController
{


    public function index(){

        $Conf=[
            'title'=>'订单页',
            'js'=>['list']
        ];

        $this->assign('Conf',$Conf);

        if(!session('?username')){
            $this->error("请您先登录",u('Home/Login/index'));exit;
        }


        $uid=$_SESSION['uid'];


       $oid=m('order')->where("uid=$uid")->getField('oid',true);

       foreach ($oid as $k=>$v){
           $data[]=m('order_list')->where("oid=$v")->select();
       }
       foreach($oid as $k=>$v){
           $time[]= m('order')->where("oid=$v")->getField('time');
       }
//       dd($time);
        foreach ($oid as $k=>$v){
            $number[]= m('order')->where("oid=$v")->getField('number');
        }


        $tame=[];
        foreach ($data as $kk=>$vv){
            $tame[$kk]['time']= $time[$kk];
            $tame[$kk]['number']= $number[$kk];
            $tame[$kk]['list']=$vv;

        }
//        dd($tame);



       $d =m('order')->alias('ord')
            ->join('__ORDER_LIST__ ol on ord.oid=ol.oid')
           ->join('__GOODS__ go on go.gid=ol.gid')
           ->where("uid=$uid")
           ->select();
//       dd($d);
        $data=[];
       foreach ($d as $k=>$v){
           $data[$v['oid']]['list'][]=$v;
       }
//        dd($cz);

        foreach ($data as $a=>$b) {
            foreach ($b['list'] as $d => $c) {
                $data[$a]['time'] = $c['time'];
                $data[$a]['number'] = $c['number'];
            }
        }
//        dd($data);

    $this->assign('data',$data);


        $this->display();
    }



}